﻿using OpenTK;

namespace Chimp.Core.PostFX
{
    public class PostFX_VolumetricLighting : ChimpPostFX
    {
        public PostFX_VolumetricLighting()
        {
            Effect = new ChimpEffect(null, "Res/Shader/PostFX_VolumetricLighting.glsl");
            Effect.SetInt("SourceMap", 0);
            Effect.SetInt("ObjectMap", 1);
        }

        public override void OnDrawPostFX(ChimpTexture2D src)
        {
            Effect.Use();
            ChimpDraw.BlendMode = ChimpBlend.Lighten;
            foreach (ChimpLight l in Scene.LightList)
            {
                Effect.SetVec2("LightPos", new Vector2((l.DrawPos.X)/ChimpApp.W, 1.0f - ((l.DrawPos.Y)/ChimpApp.H)));
                Effect.SetVec3("LightCol", l.Color);
                Effect.SetFloat("LightRange", l.Range*0.1f);
                Effect.SetVec3("ShadowCol", new Vector3(0.2f, 0.2f, 0.2f));

                ChimpDraw.Image(new Vector4(0, 0, ChimpApp.W, ChimpApp.H), src, new Vector4(1, 1, 1, 1));
            }
            Effect.Fin();
        }
    }
}